var leftObj ,rightObj,leftArray,rightArray;

window.onload = function () {
    leftObj = document.getElementById("left");
    rightObj = document.getElementById("right");
    leftArray = leftObj.getElementsByTagName("option");
    rightArray = rightObj.getElementsByTagName("option");

    var buttonArray = document.getElementById("data").getElementsByTagName("input");
    buttonArray[0].onclick = function () {
        move(leftArray,rightArray,leftObj,rightObj);
    }
    buttonArray[1].onclick = function () {
        moveAll(leftArray,rightArray,leftObj,rightObj);
    }
    buttonArray[2].onclick = function () {
        move(rightArray,leftArray,rightObj,leftObj);
    }
    buttonArray[3].onclick = function () {
        moveAll(rightArray,leftArray,rightObj,leftObj);
    }
}

function move(scrArray,targetArray,scrObj,targetObj) {
    for (var i = 0 ; i < scrArray.length;i++){
        if (scrArray[i].selected){
            var obj = scrArray[i];
            scrObj.removeChild(scrArray[i]);
            targetObj.appendChild(obj);
            i--;
        }
    }
    for (var i = 0 ; i < targetArray.length;i++){
        targetArray[i].selected = false;
    }
}

function moveAll(scrArray,targetArray,scrObj,targetObj) {
    for (var i = 0 ; i < scrArray.length;i++){
        var obj = scrArray[i];
        scrObj.removeChild(scrArray[i]);
        targetObj.appendChild(obj);
        i--;
    }
}